<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>仓库管理</el-breadcrumb-item>
      <el-breadcrumb-item>库存查询</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="搜索：">
        <el-input
          size="small"
          v-model="formInline.mname"
          placeholder="输入材料名"
        ></el-input>
      </el-form-item>
      <el-form-item label="时间跨度：">
        <el-date-picker
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="开始日期"
              v-model="formInline.startDate"
            ></el-date-picker>
            -
            <el-date-picker
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="截止日期"
              v-model="formInline.endDate"
            ></el-date-picker>
        <el-button
          size="small"
          type="primary"
          icon="el-icon-search"
          @click="search"
          >搜索</el-button
        >
        <el-button
          size="small"
          type="primary"
          icon="el-icon-printer"
          v-print="'#pdfDom'"
          >打印</el-button
        >
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table
      id="pdfDom"
      size="small"
      :data="applyData"
      highlight-current-row
      v-loading="loading"
      border
      element-loading-text="拼命加载中"
      style="width: 100%"
    >
      <el-table-column
        align="center"
        sortable
        prop="materialid"
        label="材料id"
        width="180"
      >
      </el-table-column>
      <el-table-column
        align="center"
        sortable
        prop="mname"
        label="材料名称"
        width="180"
      >
      </el-table-column>
      <el-table-column
        align="center"
        sortable
        prop="type"
        label="申请类型"
        width="110"
      >
      </el-table-column>
      <el-table-column
        align="center"
        sortable
        prop="totalquantity"
        label="总计数量"
        width="100"
      >
      </el-table-column>
      <el-table-column
        align="center"
        sortable
        prop="totalprice"
        label="总计价值"
        min-width="160"
      >
      </el-table-column>
      <el-table-column label="操作" align="center" min-width="230">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination
      v-bind:child-msg="pageparm"
      @callFather="callFather"
    ></Pagination>
    <!-- 查看界面 -->
    <el-dialog
      :title="title"
      :visible.sync="editFormVisible"
      width="60%"
      @click="closeDialog('edit')"
    >

      <el-card >
  <div v-for="o in tableData" :key="o">
    {{'申请单号 ' + o }}
  </div>
</el-card>
      <!-- 底部按钮 -->
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="closeDialog('edit')">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 导入请求方法
import {getmaterials} from "../../api/storeMG";
import { getCookie } from "../../utils/util";
import Pagination from "../../components/Pagination";
import print from "vue-print-nb";
export default {
  name: "inventory",
  data() {
    return {
      loading: false, //是显示加载
      title: "材料申请号详情",
      size: "medium",
      editFormVisible: false, //控制编辑页面显示与隐藏
      // 申请单详情对象
      tableData: {},
      // cookie中的基本用户信息对象
      user: {
        id: 0,
        role: "",
        store: "",
        storeid: 0,
        userName: "",
        useremail: "",
      },
      // 编辑与添加
      editForm: {
        notes: "",
        opinion: "",
      },
      // 请求数据参数
      formInline: {
        page: 1,
        size: 10,
        id: 0,
        storeid: 0,
        email: "",
      },
      // 数据
      applyData: [],
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10,
      },
    };
  },
  // 注册组件
  components: {
    Pagination,
    print,
  },
  /**
   * 数据发生改变
   */
  watch: {},
  /**
   * 创建完毕
   */
  created() {
    this.user = JSON.parse(getCookie("userdata"));
    this.formInline.id = this.user.id;
    this.formInline.role = this.user.role;
    this.formInline.storeid = this.user.storeid;
    this.formInline.email = this.user.useremail;
    this.getdata(this.formInline);
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    // 获取数据方法
    getdata(parameter) {
      this.loading = true;
      // 获取数据列表
      getmaterials(parameter).then((res) => {
        this.loading = false;
        if (res.status == 200) {
          this.applyData = res.data;
          console.log(res.data);
          // 分页赋值
          this.pageparm.currentPage = this.formInline.page;
          this.pageparm.pageSize = this.formInline.size;
          this.pageparm.total = res.count;
        } else {
          this.$message({
            type: "error",
            message: res.statusInfo.message,
          });
        }
      });
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage;
      this.formInline.size = parm.pageSize;
      this.getdata(this.formInline);
    },
    //搜索事件
    search() {
      this.getdata(this.formInline);
    },
    //显示详情界面
    handleEdit: function (index, row) {
      this.editFormVisible = true;
      // 把applyIds分组赋值给tableData
      this.tableData = row.applyIds.split(',')
    },
    // 关闭编辑、增加弹出框
    closeDialog(dialog) {
      if (dialog == "edit") {
        this.editFormVisible = false;
      }
    },
  },
};
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
</style>